//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer.Components;
using CommunityServer.Galleries;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Spam
{
	/// <summary>
	/// Base class for all gallery specific spam rules.
	/// Includes built-in checks for which gallery posts to process.
	/// </summary>
	public abstract class GallerySpamRule : SpamRule
	{
		/// <summary>
		/// Responsible for spam-rating a post
		/// </summary>
		/// <param name="post"></param>
		/// <param name="e"></param>
		/// <returns></returns>
		public override int RatePost(Post post, CSPostEventArgs e)
		{
			// Can we, and should we rate this post?
			GalleryPost galleryPost = post as GalleryPost;
			if ((galleryPost == null) || (IsExemptFromSpamRating(galleryPost, e)))
				return 0;

			return CalculateSpamScore(galleryPost, e);
		}


		/// <summary>
		/// Responsible for determining if this post should be spam-rated
		/// </summary>
		/// <param name="post"></param>
		/// <param name="e"></param>
		/// <returns></returns>
		public override bool IsExemptFromSpamRating(Post post, CSPostEventArgs e)
		{
			// Only rate file related content
			if (e.ApplicationType != ApplicationType.Gallery)
				return true;

			// Is this a gallery post?
			GalleryPost galleryPost = post as GalleryPost;
			if (galleryPost == null)
				return true;

			// Only check comments
			if (galleryPost.GalleryPostType != GalleryPostType.Comment)
				return true;

			// Nothing else is exempt
			return false;
		}


		/// <summary>
		/// Responsible for determining the number of spam-points to assign to this post
		/// </summary>
		/// <param name="galleryPost"></param>
		/// <param name="e"></param>
		/// <returns></returns>
		public virtual int CalculateSpamScore(GalleryPost galleryPost, CSPostEventArgs e)
		{
			return 0;
		}
	}
}
